#pragma once

#include <iostream>
#include <string>
#include <ctime>

#define INFO 1      // 信息
#define WARNING 2   // 警告
#define ERROR 3     // 错误 
#define FATAL 4     // 致命错误
#define DEBUG 5     // 调试

// 日志格式 [时间][日志级别][类名][函数名][文件名:行号]日志消息内容
#define LOG(level, message) Log(#level, message, __FILE__, __LINE__, __PRETTY_FUNCTION__, __FUNCTION__);

// 时间戳转换
std::string TimeSwitch(time_t now)
{
    tm* ltm = localtime(&now);
    std::string res;
    res += std::to_string(1900 + ltm->tm_year);
    res += "/";
    res += std::to_string(1 + ltm->tm_mon);
    res += "/";
    res += std::to_string(ltm->tm_mday);
    res += " ";
    res += std::to_string(ltm->tm_hour);
    res += ":";
    res += std::to_string(ltm->tm_min);
    res += ":";
    res += std::to_string(ltm->tm_sec);
    return res;
}

void Log(std::string level, std::string message, std::string file_name, int line, const char* className, const char* functionName)
{
    // std::cout << "[" << time(nullptr) << "][" << level << "][" << message << "][" << file_name << "][" << line << "]" << std::endl; 
    std::cout << "[" << TimeSwitch(time(nullptr)) << "][" << level << "]";  // 时间+日志等级
    std::cout << "[" << className << "][" << functionName << "]";   // 类名+函数名
    std::cout << "[" << file_name << ":" << line << "]" << message << std::endl;    // 文件名+行号+日志消息
}
